
import com.config.Config;
import com.lua.CallLua;
import com.lua.LJBridge;
import com.lua.cache.LuaCache;
import com.nioserver.lib.LuaObj;
import com.nioserver.operations.Handler;
import com.nioserver.lib.IMessageProcessor;
import com.nioserver.linklayer.Server;
import com.nioserver.io.DataReaderFactory;


import java.io.*;
import java.lang.reflect.InvocationTargetException;

public class Main {

    public static void main(String[] args) throws IOException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {


        new Config("setting.conf");

        IMessageProcessor messageProcessor = new Handler();
        LJBridge.initBridge();
        Server server = new Server(9999,
                new DataReaderFactory(),
                messageProcessor);
        server.start();
        LuaObj token = CallLua.getInstance().launch("start/setup");
        LuaCache.getService(token.address).get("setFunc").call(Config.LuaPath);
        CallLua.getInstance().launch("main");
//        LuaCache.getService(vl).get("test").call();
//        LuaValue luaOp = CallLua.getInstance().launch("main");
//        luaOp.get("call").call(LuaValue.valueOf("hello world".getBytes()));

//        Globals globals = JsePlatform.standardGlobals();
//        LuaValue chunk = globals.loadfile(luaPath+"test.lua");
//        LuaValue lv = chunk.call();
//
//        LuaValue addFunc = lv.get(("add"));
//        Date noe = new Date();
//        for(int i =0;i<100000*100;i++){
//            addFunc.call();
//        }
//        Date d2 = new Date();
//        System.out.println(d2.getTime() - noe.getTime());
//        int a = 0;
//        for (int i =0;i<100000*100;i++){
//            a++;
//        }
//        Date d3 = new Date();
//        System.out.println(d3.getTime() - d2.getTime());
    }
}
